#include <stdio.h>
#include <string.h>
char buf1[15];
char buf2[15];
char s[6];
int ref[6];
void rinit()
{
	ref[0] = 5; ref[5] = 0;
	ref[1] = 3; ref[3] = 1;
	ref[2] = 4; ref[4] = 2;
}
double calc(char x, char y)
{
	int p[10], q[10];
	int pc=0, qc=0;
	for(int i=0; i<6; i++){
		if(s[i] == x)
			p[pc++] = i;
		if(s[i] == y)
			q[qc++] = i;
	}
//	printf("pc: %d, qc: %d\n", pc, qc);
	if(pc == 0)
		return 0;
	if(x == y)
		return 1;
	double res = 0.0;
	for(int i=0; i<pc; i++){
		double t=0;
		for(int j=0; j<qc; j++){
			if(ref[p[i]] == q[j]){
				t = 1;
				goto fk;
			}
		}
		if(qc >= 3)
			t = 1;
		if(qc == 1)
			t = 0.5;
		if(qc == 2){
			if(q[0] == ref[q[1]])
				t = 0.5;
			else
				t = 1;
		}
	//	printf("t: %.3f\n", t);
fk:		res += t;
	}
	return res/pc;
}
int main()
{
	rinit();
	scanf("%s", buf1);
	scanf("%s", buf2);
	double ans = 1.0;
	int n = strlen(buf1);
	for(int i=0; i<n; i++){
		scanf("%s", s);
		ans = ans * calc(buf1[i], buf2[i]);
	}
	printf("%.7f", ans);
	return 0;
}
